<template>
  <div class="line wrap">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b">
      <el-menu-item index="/homepage"><i class="el-icon-star-off"></i>首页</el-menu-item>
      <el-menu-item index="/suppliers" ><i class="el-icon-user-solid"></i>供应商中心</el-menu-item>
      <el-menu-item index="/spstorage"><i class="el-icon-files"></i>供应商产品中心</el-menu-item>
      <el-menu-item index="/customers"><i class="el-icon-user"></i>客户中心</el-menu-item>
      <el-menu-item index="/cpstorage"><i class="el-icon-coin"></i>客户产品中心</el-menu-item>
      <el-menu-item index="/order"><i class="el-icon-document-copy"></i>销售订单中心</el-menu-item>
      <el-menu-item index="/users" v-if="status==='1'"><i class="el-icon-user"></i>用户管理中心</el-menu-item>
      <el-menu-item index="/exit"><i class="el-icon-moon-night"></i>退出登录</el-menu-item>
    </el-menu>
    <div>
      <transition name="move" mode="out-in"><router-view></router-view></transition>
    </div>
  </div>
</template>

<script>
    export default {
      data:function () {
        return {
          activeIndex: '/homepage',
          status:''
        }
      },

      components:{

      },
      created(){
        if(typeof(localStorage.username)==='undefined'||typeof(localStorage.psw)==='undefined'||typeof(localStorage.status)==='undefined'){
            this.$message.error('登录信息过期请重新登陆');
            this.$router.push('/login');
          }
        this.status=localStorage.getItem("status")
      },
      mounted(){
        this.activeIndex = this.$route.path 
      },
      methods:{
        handleSelect(key, keyPath) {
          if(typeof(localStorage.username)==='undefined'||typeof(localStorage.psw)==='undefined'||typeof(localStorage.status)==='undefined'){
            this.$message.error('登录信息过期请重新登陆');
            this.$router.push('/login');
          }
          else{
            if(key!="/exit"){
              this.$router.push(key);
            }
            else{
              this.$confirm('确定退出登录?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
              }).then(() => {
                localStorage.clear(); 
                this.$router.push('/login');
              }).catch(() => {
                this.$message({
                type: 'info',
                message: '已取消'
                });          
              });
            }
          }
        }
      }
    }
</script>

<style scoped>
  .line{
    margin-top: -55px;
  }
  .wrap{
    position: relative;
    height:100%;
    width: 100%;
    background-size: cover;
  }

</style>
